package com.zyw.crawler.services;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class RequestObj {
	public String callback="";
	public Integer page=0;//0-all
	public String typejb="T";//T-上市公司 B-两网及退市公司	默认 = T
	public String xxzqdm="";//公司名称/代码/拼音  			默认 = null 
	public String xxzrlx="";//转让类型  ,可根据前台请求获取 包含 M,T,null  M-做市 T-协议 默认 = null ajax
	public String xxhyzl="";//行业种类  默认=null ajax
	public String xxssdq="";//地区 默认=null ajax
	public String dicXxzbqs="";//主办券商 默认null ajax
	public String xxfcbj="";//创新层,基础层,null=全部
	/*------*/
	public String sortfield="xxzqdm";//排序键 默认代码 
	public String sorttype="asc";//排序方式 正序
	String [] fileType;
	Integer parent_maxTotalPage;
	Integer parent_MaxInfoNum;
	public List<String> gjz;
	
	public List<String> getGjz() {
		return gjz;
	}
	public void setGjz(List<String> gjz) {
		this.gjz = gjz;
	}
	public static String getURLEncoderString(String str) {
        String result = "";
        if (null == str) {
            return "";
        }
        try {
            result = java.net.URLEncoder.encode(str,"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }
	public static void main(String[] args) {

	}
	public Integer getParent_maxTotalPage() {
		return parent_maxTotalPage;
	}
	public void setParent_maxTotalPage(Integer parent_maxTotalPage) {
		this.parent_maxTotalPage = parent_maxTotalPage;
	}
	public Integer getParent_MaxInfoNum() {
		return parent_MaxInfoNum;
	}
	public void setParent_MaxInfoNum(Integer parent_MaxInfoNum) {
		this.parent_MaxInfoNum = parent_MaxInfoNum;
	}
	public String generateStartPage(String startPage){
		return generateStartPage(startPage, this);
	}
	public static String generateStartPage(String startPage,RequestObj obj){
		startPage=startPage.contains("?")?startPage:startPage+"?";
		String params="";
		for(Field f:obj.getClass().getFields()){
			if(f.getName().equals("gjz"))continue;
			String value="";
			try {
				value=f.get(obj).toString();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			params+=f.getName()+"="+value+"&";
		}
		params=params.lastIndexOf("&")==params.length()-1?params.substring(0,params.length()-1):params;
		startPage+=params;
		return startPage;
	}
	
	public String getCallback() {
		return callback;
	}
	public void setCallback(String callback) {
		this.callback = callback;
	}
	public Integer getPage() {
		return page;
	}
	public void setPage(Integer page) {
		this.page = page;
	}
	public String getTypejb() {
		return typejb;
	}
	public void setTypejb(String typejb) {
		this.typejb = typejb;
	}
	public String getXxzqdm() {
		return xxzqdm;
	}
	public void setXxzqdm(String xxzqdm) {
		this.xxzqdm = xxzqdm;
	}
	public String getXxzrlx() {
		return xxzrlx;
	}
	public void setXxzrlx(String xxzrlx) {
		this.xxzrlx = xxzrlx;
	}
	public String getXxhyzl() {
		return xxhyzl;
	}
	public void setXxhyzl(String xxhyzl) {
		this.xxhyzl = xxhyzl;
	}
	public String getXxssdq() {
		return xxssdq;
	}
	public void setXxssdq(String xxssdq) {
		this.xxssdq = xxssdq;
	}
	public String getDicXxzbqs() {
		return dicXxzbqs;
	}
	public void setDicXxzbqs(String dicXxzbqs) {
		this.dicXxzbqs = dicXxzbqs;
	}
	public String getXxfcbj() {
		return xxfcbj;
	}
	public void setXxfcbj(String xxfcbj) {
		this.xxfcbj = xxfcbj;
	}
	public String getSortfield() {
		return sortfield;
	}
	public void setSortfield(String sortfield) {
		this.sortfield = sortfield;
	}
	public String getSorttype() {
		return sorttype;
	}
	public void setSorttype(String sorttype) {
		this.sorttype = sorttype;
	}
	
	public String[] getFileType() {
		return fileType;
	}
	public void setFileType(String[] fileType) {
		this.fileType = fileType;
	}
	public RequestObj(String callback, Integer page, String typejb, String xxzqdm, String xxzrlx, String xxhyzl,
			String xxssdq, String dicXxzbqs, String xxfcbj, String sortfield, String sorttype) {
		super();
		this.callback = callback;
		this.page = page;
		this.typejb = typejb;
		this.xxzqdm = xxzqdm;
		this.xxzrlx = xxzrlx;
		this.xxhyzl = xxhyzl;
		this.xxssdq = xxssdq;
		this.dicXxzbqs = dicXxzbqs;
		this.xxfcbj = xxfcbj;
		this.sortfield = sortfield;
		this.sorttype = sorttype;
	}
	public RequestObj() {
		super();
	}
	public RequestObj(String xxzrlx, String xxhyzl, String xxssdq, String dicXxzbqs, String xxfcbj,String[] fileType) {
		super();
		this.xxzrlx = xxzrlx;
		this.xxhyzl = xxhyzl;
		//转码直接写到这了
		this.xxssdq =getURLEncoderString(getURLEncoderString(xxssdq));
		this.dicXxzbqs = dicXxzbqs;
		this.xxfcbj = xxfcbj;
		this.fileType=fileType;
	}
	public void addGjz(String[] gjzs) {
		 List<String> l=new ArrayList<String>();
		  for(String s:PdfReader.defGuanJianZi){
			  l.add(s);
		  }
		  for(String s:gjzs){
			  if(!s.trim().equals("")){
				  l.add(s);
			  }
		  }
		  this.gjz=l;
	}

	
}
